using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;
using RegionInterface;
namespace RegionData
{
    public class PlayerManager : IPlayerManager
    {
        private RegionData dataHandle = null;
        private Timer updateTimer = null;
        private TaskReady taskList = null;

        public bool Init(string connectString, string ip, int port)
        {
            return true;
            bool result = false;
            taskList = new TaskReady(1000);
            taskList.Init();
            dataHandle = new RegionData();
            if (dataHandle.Init(connectString, ip, port))
            {
                updateTimer = new Timer(Constant.UpdateInterval * 1000);
                updateTimer.Elapsed += delegate(object sender, ElapsedEventArgs e)
                {
                    dataHandle.UpdateState();
                };
                updateTimer.Start();
                result = true;
            }
            return result;
        }
        public int AddDomain(int backgroundId, string name)
        {
            return 1;
            return dataHandle.AddDomain(backgroundId, name);
        }
        public bool DeleteDomain(int regionId)
        {
            return true;
            return dataHandle.DeleteDomain(regionId);
        }
        public bool AddPlayer(int backgroundId, int regionId, int playerId, int count)
        {
            return true;
            return dataHandle.AddPlayer(backgroundId, regionId, playerId, count);
        }
        public bool DeletePlayer(int backgroundId, int regionId, int playerId, int count)
        {
            return true;
            return dataHandle.DeletePlayer(backgroundId, regionId, playerId, count);
        }
        public bool Close()
        {
            return true;
            updateTimer.Stop();
            dataHandle.Close();
            return true;
        }
        public bool OnMessage(int from, int to, int type, string content, string tick)
        {
            //taskList.TaskSync(delegate()
            //{
            //    switch (type)
            //    {
            //        case "chat":
            //            {
            //                Log.ChatLog(from.ToString(), to.ToString(), type.ToString(), content);
            //                break;
            //            }
            //        default:
            //            {
            //                break;
            //            }
            //    }
            //});
            return true;
        }
    }
}
